<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/layui-src@2.6.4/dist/css/layui.css">
    <script src="//cdn.jsdelivr.net/npm/layui-src@2.6.4/dist/layui.js"></script>
</head>
<body>

<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
        <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
        <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
    </div>
</script>
<!--<script type="text/html" id="barDemo">-->
<!--    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>-->
<!--    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>-->
<!--</script>-->


<script src="//res.layui.com/layui/dist/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->

<script th:inline="none">
    layui.use('table', function(){
        var table = layui.table;

        //温馨提示：默认由前端自动合计当前行数据。从 layui 2.5.6 开始： 若接口直接返回了合计行数据，则优先读取接口合计行数据。
        //详见：https://www.layui.com/doc/modules/table.html#totalRow
        table.render({
            elem: '#test'
            ,url:'/report/logging'
            ,title: '日志表'
            ,totalRow: true
            ,response:{
                countName:'count',
                dataName:'datas'
            }
            ,cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field:'eventId', title: 'ID', sort: true}
                ,{field:'timestmp', width:180, title: 'timestmp', sort: true,templet: "<div>{{layui.util.toDateString(d.createTime, 'yyyy-MM-dd HH:mm:ss')}}</div>"}
                ,{field:'formattedMessage', width:280, title: 'formatted_message', sort: true}
                ,{field:'loggerName', width:380, title: 'logger_name', sort: true}
                ,{field:'levelString', width:80, title: 'level_string', sort: true}
                ,{field:'threadName', width:140, title: 'thread_name', sort: true}
                ,{field:'referenceFlag', width:80, title: 'reference_flag', sort: true}
                ,{field:'arg0', width:80, title: 'arg0', sort: true}
                ,{field:'arg1', width:80, title: 'arg1', sort: true}
                ,{field:'arg2', width:80, title: 'arg2', sort: true}
                ,{field:'arg3', width:80, title: 'arg3', sort: true}
                ,{field:'callerFilename', width:280, title: 'caller_filename', sort: true}
                ,{field:'callerClass', width:280, title: 'caller_class', sort: true}
                ,{field:'callerMethod', width:280, title: 'caller_method', sort: true}
                ,{field:'callerLine', width:80, title: 'caller_line', sort: true}
                // ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}
            ]]
            ,page: true
        });

        //工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckData':
                    var data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：'+ data.length + ' 个');
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选': '未全选')
                    break;
            };
        });

        //监听工具条
        table.on('tool(demo)', function(obj){
            var data = obj.data;
            if(obj.event === 'detail'){
                layer.msg('ID：'+ data.id + ' 的查看操作');
            } else if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    obj.del();
                    layer.close(index);
                });
            } else if(obj.event === 'edit'){
                layer.alert('编辑行：<br>'+ JSON.stringify(data))
            }
        });
    });

</script>

</body>
</html>